package com.erp.erp_mask.controller;

import com.erp.erp_mask.mapper.THouseMapper;
import com.erp.erp_mask.mapper.TPartwareMapper;
import com.erp.erp_mask.mapper.TPropurMapper;
import com.erp.erp_mask.pojo.*;
import com.erp.erp_mask.service.THouseService;
import com.erp.erp_mask.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/pan")
public class THouseController {
    @Resource
    private THouseService tHouseService;

    @Resource
    private  THouseMapper tHouseMapper;
    @Resource
    private TPropurMapper tPropurMapper;
    @Resource
    private TPartwareMapper tPartwareMapper;
    @GetMapping("/index")
    public ModelAndView modelAndView(){
        return new ModelAndView("/pan/panshen");
    }

    @GetMapping("/xiansearch")
    public Result index(String seData, String comeTime,Long pageNo,Long pageSize){
        return Result.success(tHouseService.searchpan(seData,comeTime,pageNo,pageSize)
        );
    }

    @Transactional
    @PostMapping("/addhouse")
    public Result addList(@RequestBody THouse tHouse) {
        try {
            System.out.println(tHouse);
            tPropurMapper.addhouse(tHouse);
            tHouseMapper.edithoust(tHouse);
            return Result.success("添加成功!");
        } catch (Exception e) {
            return Result.fail("添加失败!");
        }
    }
    @PutMapping("/update")
    public Result update(@RequestBody THouse tHouse){
        try {
            System.out.println(tHouse);
            tHouseMapper.edithoue(tHouse);
            return Result.success("修正成功！");
        }catch (Exception e){
            return Result.fail("修正失败!");
        }
    }
}
